import 'package:flutter/services.dart';
import 'package:flutter_cli/theme/theme.dart';
import 'package:flutter_cli/utils/common.dart';

PreferredSizeWidget mainBar(title,
    {isGradient = false,
    backGround,
    textColor,
    isBack = true,
    status,
    centerTitle = true,
    ele = 4.0,
    List<Widget>? actionsList}) {
  return AppBar(
    automaticallyImplyLeading: isBack,
    systemOverlayStyle: SystemUiOverlayStyle(
        statusBarIconBrightness: status ?? Brightness.dark),
    elevation: 0,
    title: Text(
      title,
      style: TextStyle(
          color: textColor ?? Get.theme.textTheme.displayLarge?.color,
          fontSize: 36.w,
          fontWeight: FontWeight.w600),
    ),
    iconTheme: IconThemeData(
        color: textColor ?? Get.theme.textTheme.displayLarge?.color),
    flexibleSpace: isGradient
        ? Container(
            decoration: const BoxDecoration(
                gradient: LinearGradient(colors: [
              Color.fromRGBO(19, 173, 143, 1),
              Color.fromRGBO(231, 62, 89, 1)
            ], begin: Alignment.centerLeft, end: Alignment.centerRight)),
          )
        : Container(),
    actions: actionsList,
    centerTitle: centerTitle,
    backgroundColor: backGround ?? Get.theme.scaffoldBackgroundColor,
  );
}

/// 常规Toast
void hkShowToast(String text,
    {duration = 2000, GestureTapCallback? onDismiss}) {
  // primaryColorDark
  showToast(text,
      backgroundColor: (global.theme.value == ThemeStyle.dark.value
              ? Colors.white
              : Colors.black)
          .withOpacity(0.8),
      textStyle: TextStyle(
        color: global.theme.value == ThemeStyle.dark.value
            ? Colors.black
            : Colors.white,
        fontSize: 16,
      ),
      duration: Duration(milliseconds: duration),
      dismissOtherToast: true,
      onDismiss: onDismiss);
}

/// 取消Toast
void hkCancelToast() {
  dismissAllToast();
}

showAlert(
  context, {
  String title = '温馨提示',
  Widget? child,
  String content = '',// 默认内容
  Function? confirm,
  Function? cancel,
  String confirmText = '确定',
  String cancelText = '取消',
}) {
  return showDialog(
      context: context,
      barrierDismissible: false,
      builder: (BuildContext context) {
        return AlertDialog(
          contentPadding: EdgeInsets.all(24.0.w),
          elevation: 10.0,
          backgroundColor: Get.theme.primaryColorLight,
          shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(20.0.w)),
          title: Container(
            alignment: Alignment.center,
            child: Text(
              title,
              style: TextStyle(
                  color: Get.theme.textTheme.displayLarge?.color,
                  fontSize: 36.0.sp,
                  fontWeight: FontWeight.bold),
            ),
          ),
          content: child ??
              Container(
                child: Text(
                  content.tr,
                  textAlign: TextAlign.center,
                  style: TextStyle(
                      fontSize: 32.0.sp,
                      color: Get.theme.textTheme.displayLarge?.color),
                ),
              ),
          actions: <Widget>[
            Container(
              width: 600.0.w,
              padding: EdgeInsets.symmetric(horizontal: 20.0.w),
              margin: EdgeInsets.only(bottom: 20.0.w),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  InkWell(
                    borderRadius: BorderRadius.circular(44.0.w),
                    onTap: () {
                      if (cancel != null) {
                        cancel!();
                      }
                      Get.back();
                    },
                    child: Container(
                      width: 240.0.w,
                      height: 88.0.w,
                      alignment: Alignment.center,
                      decoration: BoxDecoration(
                          borderRadius: BorderRadius.circular(44.0.w),
                          border: Border.all(
                              color: Get.textTheme.bodyLarge?.color ?? Colors.grey, width: 1.w)),
                      child: Text(
                        cancelText.tr,
                        style: TextStyle(
                          color: Get.textTheme.bodyLarge?.color,
                          fontWeight: FontWeight.bold,
                          fontSize: 30.0.w,
                        ),
                      ),
                    ),
                  ),
                  InkWell(
                    borderRadius: BorderRadius.circular(44.0.w),
                    onTap: () {
                      if (confirm != null) {
                        confirm!();
                      }
                      Get.back();
                    },
                    child: Container(
                      width: 240.0.w,
                      height: 88.0.w,
                      alignment: Alignment.center,
                      decoration: BoxDecoration(
                          color: Get.theme.primaryColor,
                          borderRadius: BorderRadius.circular(44.0.w)),
                      child: Text(
                        confirmText.tr,
                        style: TextStyle(
                            color: Get.theme.textTheme.headlineSmall?.color,
                            fontWeight: FontWeight.bold,
                            fontSize: 30.0.w),
                      ),
                    ),
                  )
                ],
              ),
            )
          ],
        );
      });
}
